#include "t_at_port.h"

#include "t_at.h"




/*at time tick*/
uint32_t volatile at_time_tick = 0;
/*RTOS  lock  handle*/

/**
 * @brief This function is used to simulate the delay of the AT command module.
 */
void t_at_1ms(void) { at_time_tick++; }
/**
 * @brief This function is used to get the current time tick of the AT command module.
 */
uint32_t t_at_get_tick(void) { return at_time_tick; }
/**
 * @brief This API is used to create a lock for the AT command module by RTOSAPI.
 */
#if T_AT_RTOS_API_EN
#define T_os_func 1
#define CMD_RCV_CPLT (1 << 0)

/**
 * @brief This API is used to initialize the lock of the AT command module by RTOSAPI.
 * @param os The lock handle.
 * @return T_OSLokType The result of the initialization operation.
 */
T_OSLokType t_at_os_init_t(void *os) {
    *(EventGroupHandle_t *)os = xEventGroupCreate();
    if (*(EventGroupHandle_t *)os == NULL) {
        return T_OS_ERROR;
    }
    return T_OS_OK;
}
/**
 * @brief This API is used to lock the lock of the AT command module by RTOSAPI.
 * @param os The lock handle.
 * @param locktime The lock time.
 * @return T_OSLokType The result of the lock operation.
 * @note  .

*/
T_OSLokType t_at_os_lock_t(void *os, uint32_t locktime) {
    if (os == NULL) {
        return T_OS_ERROR;
    }
    if (xEventGroupWaitBits(*(EventGroupHandle_t *)os, CMD_RCV_CPLT, pdTRUE, pdFALSE, locktime) ==
        pdPASS) {
        return T_OS_OK;
    }
    return T_OS_TIMOUT;
}
/**
 * @brief This API is used to unlock the lock of the AT command module by RTOSAPI.
 * @param os The lock handle.
 * @return T_OSLokType The result of the unlock operation.
 * @note   If receiving data in interrupt please use RTOS API with suffix ISR
 */
T_OSLokType t_at_os_unlock_t(void *os) {
    if (os == NULL) {
        return T_OS_ERROR;
    }
    xEventGroupSetBitsFromISR(*(EventGroupHandle_t *)os, CMD_RCV_CPLT, 0); /*note*/
    return T_OS_OK;
}




#endif
/*RTOS中断处理将整包的数据丢进去*/
/*
void UART4_IRQHandler(void)
{
	HAL_UART_IRQHandler(&slm_huart4);
	if(__HAL_UART_GET_FLAG(&slm_huart4,UART_FLAG_IDLE)!= RESET)//idle标志被置位
	{ 
		__HAL_UART_CLEAR_IDLEFLAG(&slm_huart4);//清除标志位
		HAL_UART_DMAStop(&slm_huart4); //
		rx4_len = BUFFER_SIZE - __HAL_DMA_GET_COUNTER(&slm_hdma_uart4_rx);// 获取DMA中未传输的数据个数
        HAL_UART_Receive_DMA(&slm_huart4, (uint8_t *)rx4_buffer, BUFFER_SIZE);//DMA接收
       //HAL_UART_Transmit_DMA(&slm_huart4, (uint8_t *)rx4_buffer,rx4_len);//打环处理
		if(rx4_len>0) 
		{
		 recv4_end_flag = 1;	// 接受完成标志位置1	
		 t_at_rev_push_rbf(SLM,rx4_buffer,rx4_len);//MG 处理线程
			
			
		}
	 }
}
*/
